using System;
using UnityEngine;
using QFramework;
using UnityEngine.EventSystems;

namespace ProjectMyFarmAndShe
{
	public partial class EmailItemTemplate : ViewController,IPointerClickHandler
	{
		private EmailData mData;
		private Action<EmailData> OnPointerClickAction;
		
		void Start()
		{
			// Code Here
		}

		public void Init(EmailData data)
		{
			mData = data;

			TitleText.text = mData.Title;
			mData.IsRead.RegisterWithInitValue(isRead =>
				{
					IsReadText.text = isRead ? "已读" : "未读";
				})
				.UnRegisterWhenGameObjectDestroyed(gameObject);
		}

		public void SetPointerClickAction(Action<EmailData> action)
		{
			OnPointerClickAction = action;
		}

		public void OnPointerClick(PointerEventData eventData)
		{
			OnPointerClickAction?.Invoke(mData);
		}
	}
}
